package m2;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.*;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.message.MessageExt;

import java.util.List;

/**
 * @description:
 * @author: LiuXingYu
 * @date: 2021/9/24 17:50
 */
public class Consumer {

    public static void main(String[] args) throws MQClientException {

        DefaultMQPushConsumer c = new DefaultMQPushConsumer("cons-group2");

        c.setNamesrvAddr("192.168.64.141:9876");

        c.subscribe("topic2", "*");

        c.setMessageListener(new MessageListenerOrderly() {
            @Override
            public ConsumeOrderlyStatus consumeMessage(List<MessageExt> list, ConsumeOrderlyContext consumeOrderlyContext) {

                for (MessageExt ext : list) {
                    String s = new String(ext.getBody());
                    System.out.println("收到: " + s);
                }
                return ConsumeOrderlyStatus.SUCCESS;
            }
        });

        c.start();
    }
}
